<?php
class ShareVo extends SzAbstractMySqlVo
{

    private $userId;
    private $shareCode;
    private $shareId;
    private $touchUsers;
    private $shareTime;
    private $isGetReward;
    private $cultivateTouchUsers;

    /**
     * Initialize ShareVo.
     *
     * @param $userId
     * @param $shareCode
     * @param $shareId
     * @param $touchUsers
     * @param $shareTime
     * @param $isGetReward
     * @param $cultivateTouchUsers
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return ShareVo
     */
    public function __construct($userId, $shareCode, $shareId, $touchUsers, $shareTime, $isGetReward, $cultivateTouchUsers, $isInsert = false) {
        $this->userId = $userId;
        $this->shareCode = $shareCode;
        $this->shareId = $shareId;
        $this->touchUsers = json_decode($touchUsers, true);
        $this->shareTime = $shareTime;
        $this->isGetReward = $isGetReward;
        $this->cultivateTouchUsers = json_decode($cultivateTouchUsers, true);

        $this->isInsert = $isInsert;
        $this->voClassName = 'ShareVo';
        $this->ormName = 'Share';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'shareCode' => $this->getShareCode(),
            'shareId' => $this->getShareId(),
            'touchUsers' => ($needEncode) ? $this->getTouchUsers() : $this->getRawTouchUsers(),
            'shareTime' => $this->getShareTime(),
            'isGetReward' => $this->getIsGetReward(),
            'cultivateTouchUsers' => ($needEncode) ? $this->getCultivateTouchUsers() : $this->getRawCultivateTouchUsers(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'shareCode' => $this->getShareCode(),
            'shareId' => $this->getShareId(),
            'touchUsers' => ($needEncode) ? $this->getTouchUsers() : $this->getRawTouchUsers(),
            'shareTime' => $this->getShareTime(),
            'isGetReward' => $this->getIsGetReward(),
            'cultivateTouchUsers' => ($needEncode) ? $this->getCultivateTouchUsers() : $this->getRawCultivateTouchUsers(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getShareCode(),
            $this->getShareId(),
            $this->getTouchUsers(),
            $this->getShareTime(),
            $this->getIsGetReward(),
            $this->getCultivateTouchUsers(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getShareCode()
    {
        return $this->shareCode;
    }

    public function setShareCode($val)
    {
        $this->saveColumnStatus(1, $this->shareCode);
        $this->shareCode = $val;
    }

    public function getShareId()
    {
        return $this->shareId;
    }

    public function setShareId($val)
    {
        $this->saveColumnStatus(2, $this->shareId);
        $this->shareId = $val;
    }

    public function getTouchUsers()
    {
        return json_encode($this->touchUsers);
    }

    public function getRawTouchUsers()
    {
        return $this->touchUsers;
    }

    public function setTouchUsers($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 218400) {
            SzLogger::get()->error('[ShareVo] The length of column touchUsers exceed the limit, length / limit: ' . $encodedLength . ' / 218400');
            throw new SzException(10522, array('ShareVo', '218400', $encodedLength));
        } else if ($encodedLength > 196560) {
            SzLogger::get()->warn('[ShareVo] The length of column touchUsers exceed the warning level, length / limit: ' . $encodedLength . ' / 218400');
        }
        $this->saveColumnStatus(3, $this->touchUsers);
        $this->touchUsers = $val;
    }

    public function getShareTime()
    {
        return $this->shareTime;
    }

    public function setShareTime($val)
    {
        $this->saveColumnStatus(4, $this->shareTime);
        $this->shareTime = $val;
    }

    public function getIsGetReward()
    {
        return $this->isGetReward;
    }

    public function setIsGetReward($val)
    {
        $this->saveColumnStatus(5, $this->isGetReward);
        $this->isGetReward = $val;
    }

    public function getCultivateTouchUsers()
    {
        return json_encode($this->cultivateTouchUsers);
    }

    public function getRawCultivateTouchUsers()
    {
        return $this->cultivateTouchUsers;
    }

    public function setCultivateTouchUsers($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 218400) {
            SzLogger::get()->error('[ShareVo] The length of column cultivateTouchUsers exceed the limit, length / limit: ' . $encodedLength . ' / 218400');
            throw new SzException(10522, array('ShareVo', '218400', $encodedLength));
        } else if ($encodedLength > 196560) {
            SzLogger::get()->warn('[ShareVo] The length of column cultivateTouchUsers exceed the warning level, length / limit: ' . $encodedLength . ' / 218400');
        }
        $this->saveColumnStatus(6, $this->cultivateTouchUsers);
        $this->cultivateTouchUsers = $val;
    }

}